package base.dao;

import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : GuoFei
 * @date : 2018/12/22 10:42
 */
@Repository
public class SqlServerTestDao{

    @Autowired
    private BaseDao baseDao;

    public List get(boolean canRun) {
        if (!canRun) {
            throw  new RuntimeException("不让通过---get");
        }
        String sql = "select * from testuser";
        return baseDao.getList(sql);
    }

    public int add(boolean canRun,String name,String password){
        if (!canRun) {
            throw  new RuntimeException("不让通过---add");
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 1000; i++) {
            sb.append("('");
            sb.append(name).append(String.valueOf(i)).append("','").append(password);
            sb.append("'),");
        }
        sb.deleteCharAt(sb.length() - 1);
        String sql = "insert into userTest (name,password) values "+sb.toString()+";";
        return baseDao.add(sql);
    }

    public JSONArray list(int num){
        String sql = "selelct * from testUser order by id desc";
        return baseDao.listJSON(sql,num);
    }

}
